/**
 * @(#)RetentFillConfigTimerServiceImpl.java 2017年11月28日
 * Copyright(C) 2017 ZHEXIN IT CO.,LTD. All rights reserved.
 */
package org.jsbd.boss.service.impl;

import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

import javax.annotation.Resource;

import org.apache.commons.lang.time.DateFormatUtils;
import org.jsbd.boss.dao.IRetentFillConfigTimerDAO;
import org.jsbd.boss.dao.IRetentLogConfigDAO;
import org.jsbd.boss.domian.channel.RetentLogConfig;
import org.jsbd.boss.service.IRetentFillConfigTimerService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;

/**
 * TODO 请加入本类的说明
 * 
 * @author <a href="mailto:xupengcheng@zhexinit.com" >徐鹏程</a>
 * @version 1.0.0
 */
@Service
public class RetentFillConfigTimerServiceImpl implements IRetentFillConfigTimerService {
	public static final Logger LOGGER = LoggerFactory.getLogger(RetentFillConfigTimerServiceImpl.class);

	@Resource
	private IRetentFillConfigTimerDAO retentFillConfigTimerDAO;

	@Resource
	private IRetentLogConfigDAO retentLogConfigDAO;

	/*
	 * (non-Javadoc)
	 * 
	 * @see
	 * org.jsbd.boss.service.IRetentFillConfigTimerService#selectRetentLogConfigList
	 * (org.jsbd.boss.domian.channel.RetentLogConfig)
	 */
	@Override
	public List<RetentLogConfig> selectRetentLogConfigList(RetentLogConfig log) {
		return retentFillConfigTimerDAO.selectRetentLogList(log);
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see
	 * org.jsbd.boss.service.IRetentFillConfigTimerService#deleteRetentLogConfig
	 * (org.jsbd.boss.domian.channel.RetentLogConfig)
	 */
	@Override
	public void deleteRetentLogConfig(RetentLogConfig log) {
		retentFillConfigTimerDAO.delete(log);
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see
	 * org.jsbd.boss.service.IRetentFillConfigTimerService#batchInsertConfig
	 * (org.jsbd.boss.domian.channel.RetentLogConfig[])
	 */
	@Override
	public void batchInsertConfig(List<RetentLogConfig> logList) {
		retentFillConfigTimerDAO.batchInsert(logList);
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see
	 * org.jsbd.boss.service.IRetentFillConfigTimerService#updateConfigOfTimer()
	 */
	@Override
	public void updateConfigOfTimer() {
		RetentLogConfig retentLogConfig = new RetentLogConfig();
		retentLogConfig.setTimerDay(Integer.parseInt(DateFormatUtils.format(System.currentTimeMillis(), "yyyyMMdd")));
		List<RetentLogConfig> configList = retentFillConfigTimerDAO.selectRetentLogList(retentLogConfig);
		if (configList != null) {
			Set<String> apkSet = new HashSet<String>();
			List<RetentLogConfig> targetList = new ArrayList<RetentLogConfig>();
			for (RetentLogConfig config : configList) {
				apkSet.add(config.getMark());
				targetList.add(config);
			}
//			隔天的不删除 运营自己控制 
//			RetentLogConfig tempConfig = new RetentLogConfig();
//			for (String apk : apkSet) {
//				tempConfig.setMark(apk);
//				retentLogConfigDAO.deleteConfig(tempConfig);
//			}
			retentLogConfigDAO.batchInsertConfigs(configList);
		}
	}

}
